package com.tiger.novelcrazyper.base;

import java.io.BufferedReader;
import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.tiger.novelcrazyper.R;

import net.youmi.android.AdListener;
import net.youmi.android.AdView;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.AssetManager;
import android.graphics.Color;
import android.net.Uri;
import android.util.Log;
import android.view.Gravity;
import android.widget.FrameLayout;

public class CommonUtil {
	public static String fileSuffix = ".txt";
	public static String filePath = "";
	public static interface sendMessage{
		public static final int READ_TXT=0X01;
	}
	public static interface listnerKeys{
		public static final String read_key="ReadActivityResponse";
	}
	public static void setAdView(Activity act, AdListener listener) {
		// 初始化广告视图
		AdView adView = new AdView(act, Color.GRAY, Color.WHITE, 100);

		// 设置监听者(可以不设置，对获取广告没有影响)
		adView.setAdListener(listener);

		FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(
				FrameLayout.LayoutParams.FILL_PARENT,
				FrameLayout.LayoutParams.WRAP_CONTENT);

		// 设置广告出现的位置(悬浮于底部)
		params.bottomMargin = 0;
		params.gravity = Gravity.BOTTOM;
		adView.setBackgroundColor(R.color.clr_blue);
		// 将广告视图加入Activity中
		act.addContentView(adView, params);
	}

	public static String getTextByTxt(Context context, String txtNum) {
		String text = "";
		String fileName = txtNum + fileSuffix;
		AssetManager am = context.getAssets();
		InputStream is = null;
		try {
			is = am.open(fileName);
			BufferedReader reader = new BufferedReader(
					new InputStreamReader(is));
			StringBuilder sb = new StringBuilder("");
			String line = null;
			while ((line = reader.readLine()) != null) {
				sb.append(line + "\n");
			}
			text=sb.toString();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			try {
				is.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return text;
	}
}
